
#ifndef PT_GOD_SCHEDULE_H__
#define PT_GOD_SCHEDULE_H__

#ifdef __cplusplus
extern "C" {
#endif

#include "ptdef.h"
#include <stdint.h>

enum init_type{
	INIT_OK,
	INIT_EXCEED_MAX,
	INIT_NO_ENTRY,
	INIT_RE_INIT,
};
void pt_god_schedule(void);
struct pt *pt_thread_create( uint16_t thread_id, PT_THREAD( (*entry)(struct pt *pt) ) );
uint8_t pt_thread_init(struct pt *pt_ins, PT_THREAD(  (*entry)(struct pt *pt) ) );
uint8_t pt_set_thread_id(struct pt *pt_ins, uint16_t id_val);

#define PT_THREAD_INIT(pt_ins, entry, id)   \
do{     \
    pt_thread_init(pt_ins, entry);      \
    pt_set_thread_id(pt_ins, id);                     \
}while(0)

int32_t pt_thread_sleep(int32_t tick);
struct pt *get_cur_thread(void);
void pt_schedule_insert_thread(struct pt *thread);
int32_t pt_thread_suspend(struct pt *thread);
int32_t pt_thread_resume(struct pt *thread);

#define PT_THREAD_SLEEP(ticks)				\
	do {						\
		pt_thread_sleep(ticks); \
		PT_WAIT_UNTIL( pt, timer_expired(&pt->thread_timer) );           \
	} while(0)

#define PT_THREAD_DELAY(ticks)				PT_THREAD_SLEEP(ticks)

#define PT_THREAD_MDELAY(ms)				PT_THREAD_SLEEP( MS_TO_TICK(ms) )

#ifdef __cplusplus
}
#endif

#endif // PT_GOD_SCHEDULE_H__

